<template>
  <div class="">
    <van-tabs>
      <van-tab title="全部"></van-tab>
      <van-tab
      v-for="category in categories"
      :key="category.id"
       :title="category.name"
       color="#492321"
       >
      </van-tab>
  </van-tabs>
  <van-list
    v-model="loading"
    :finished="finished"
    finished-text="没有更多了"
    @load="onLoad"
    class="prod-list"
    title-active-color="#492321"
  >
    <div
    v-for="item in  all"
    :key="item.id"
    class="prod-item"
    >
    <img v-lazy="item.cover.pc_cover"/>
    <div>{{item.name}}</div>
    <div>￥{{item.specs.price}}</div>
    </div>

   <!-- </van-grid> -->
  </van-list>
  </div>

</template>

<script>
import request from '@/utils/request'
// import { getMore } from '@/api/category'
export default {
  name: 'Category',
  data () {
    return {
      categories: [],
      all: [],
      list: [],
      loading: true,
      finished: true,
      nextIndex: 0
    }
  },

  methods: {
    onLoad () {
      // 异步更新数据
      // setTimeout 仅做示例，真实场景中一般为 ajax 请求
      setTimeout(() => {
        for (let i = 0; i < 10; i++) {
          this.list.push(this.list.length + 1)
        }

        // 加载状态结束
        this.loading = false

        // 数据全部加载完成
        if (this.list.length >= 40) {
          this.finished = true
        }
      }, 1000)
    }

  },
  created () {
    const getCategory = () => request({
      url: 'category?shop_id=4',
      method: 'GET'
    })
    getCategory()
      .then(res => {
        console.log(res)
        this.categories = res
      })
    const allGetCategory = () => request({
      url: 'product?shop_id=4&category_id=0&page=1&page_size=8&discount=0&gradeSpecIds=',
      method: 'GET'
    })
    allGetCategory()
      .then(res => {
        this.all = res.data
        console.log('全部', this.all)
      })
  }

}
</script>

<style lang="scss" scoped>
  .prod-list {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;

    .prod-item {
      width: 48%;
      margin: 10px 0;
    }
     img {
       width: 100%;
    }
  }
</style>
